package com.ruoyi.business.service.impl;

import com.ruoyi.business.domain.SceneProcessParametersVersion;
import com.ruoyi.business.mapper.SceneProcessParametersVersionMapper;
import com.ruoyi.business.service.ISceneProcessParametersVersionService;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.UniqueIdGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 场景流程参数版本表Service业务层处理
 *
 * @author ruoyi
 * @date 2025-09-05
 */
@Service
public class SceneProcessParametersVersionServiceImpl implements ISceneProcessParametersVersionService
{
    @Autowired
    private SceneProcessParametersVersionMapper sceneProcessParametersVersionMapper;

    /**
     * 查询场景流程参数版本表
     *
     * @param id 场景流程参数版本表主键
     * @return 场景流程参数版本表
     */
    @Override
    public SceneProcessParametersVersion selectSceneProcessParametersVersionById(Long id)
    {
        return sceneProcessParametersVersionMapper.selectSceneProcessParametersVersionById(id);
    }

    /**
     * 查询场景流程参数版本表列表
     *
     * @param sceneProcessParametersVersion 场景流程参数版本表
     * @return 场景流程参数版本表
     */
    @Override
    public List<SceneProcessParametersVersion> selectSceneProcessParametersVersionList(SceneProcessParametersVersion sceneProcessParametersVersion)
    {
        return sceneProcessParametersVersionMapper.selectSceneProcessParametersVersionList(sceneProcessParametersVersion);
    }

    /**
     * 新增场景流程参数版本表
     *
     * @param sceneProcessParametersVersion 场景流程参数版本表
     * @return 结果
     */
    @Override
    public int insertSceneProcessParametersVersion(SceneProcessParametersVersion sceneProcessParametersVersion)
    {
        sceneProcessParametersVersion.setCreateTime(DateUtils.getNowDate());
        //自动产生功能参数编码，并保证唯一
        String parameterCode;
        SceneProcessParametersVersion searchSceneProcessParametersVersion = new SceneProcessParametersVersion();
        while (true) {
            parameterCode = UniqueIdGenerator.getUniqueClassName(10);
            searchSceneProcessParametersVersion.setParameterCode(parameterCode);
            List<SceneProcessParametersVersion> list = sceneProcessParametersVersionMapper.selectSceneProcessParametersVersionList(searchSceneProcessParametersVersion);
            if (list.size() == 0) {
                sceneProcessParametersVersion.setParameterCode(parameterCode);
                break;
            }
        }
        return sceneProcessParametersVersionMapper.insertSceneProcessParametersVersion(sceneProcessParametersVersion);
    }

    /**
     * 修改场景流程参数版本表
     *
     * @param sceneProcessParametersVersion 场景流程参数版本表
     * @return 结果
     */
    @Override
    public int updateSceneProcessParametersVersion(SceneProcessParametersVersion sceneProcessParametersVersion)
    {
        sceneProcessParametersVersion.setUpdateTime(DateUtils.getNowDate());
        return sceneProcessParametersVersionMapper.updateSceneProcessParametersVersion(sceneProcessParametersVersion);
    }

    /**
     * 批量删除场景流程参数版本表
     *
     * @param ids 需要删除的场景流程参数版本表主键
     * @return 结果
     */
    @Override
    public int deleteSceneProcessParametersVersionByIds(Long[] ids)
    {
        return sceneProcessParametersVersionMapper.deleteSceneProcessParametersVersionByIds(ids);
    }

    /**
     * 删除场景流程参数版本表信息
     *
     * @param id 场景流程参数版本表主键
     * @return 结果
     */
    @Override
    public int deleteSceneProcessParametersVersionById(Long id)
    {
        return sceneProcessParametersVersionMapper.deleteSceneProcessParametersVersionById(id);
    }
}
